<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>车源列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
            <div class="fieldBox" >
                <div class="label">车源编号</div>
                <div class="field">
                    <input name="carNo" id="carNo" type="text"   class="ui-textbox" value="">
                </div>
            </div>

            <div class="clearFix"></div>
            <div class="btnsBox">
               <span id="searchBtn" class="sq-button sq-button-round" onclick="searchBtn()">查询</span>
              <span id="clearBtn" class="sq-button sq-button-round" onclick="clearBtn()">清空</span>
             <span id="detailBtn" class="sq-button sq-button-round" onclick="detailBtn()">确定</span>
            </div>
        </div>
    </form>
</div>
<div id="ligergrid1" class="sq-grid"></div>
</div>

<script type="text/javascript">
    var grid = null;
    var prjId= '${prjId}';
    $(function () {
        prdGrid();
    });
    //根据产品类型加载不同的grid
    function prdGrid(){
        // 车源编号
        var carNo = $("#carNo").val();

        $("#ligergrid1").ligerGrid({
            url: '<%=path%>/project/vehicleSrc/initList.do',
            method : 'get',
            parms : {mhCarNo:carNo,prjId:prjId},
            columns: [
                { display: '车源编号', name: 'carNo', minWidth: 150 ,
                    enabledSort:true},
                { display: '车型名称', name: 'styleName', minWidth: 150 ,
                    enabledSort:true},
                { display: '车主姓名', name: 'ownerNm', minWidth: 150 ,
                    enabledSort:true},
                { display: 'VIN码', name: 'vin', minWidth: 140 , enabledSort:true},
                { display: '验车状态', name: 'carState', minWidth: 100 , enabledSort:true},
            ],
            pageSize:10,
            root:'rows',
            record:'total',
            hideLoadButton : true,
            width: '100%',
            height:'100%',
            heightDiff:-2,
            //isScroll: false,
            checkbox:true,
            rownumbers:true
        });
        grid = liger.get("ligergrid1");
    }

    function searchBtn(){
        prdGrid();
    }
    
    function detailBtn(){
        var prdCd = null;
        var bizTypCd = null;
        var bizCd = null;
        var sGrpCd = null;
        var sCode = null;
        var prdTypCdNm = null
        
        var selectedRows = grid.getSelectedRows();
        if(selectedRows.length != 1){
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warring"});
            return;
        }
        var carNo = selectedRows[0].carNo;
        var _url = '<%=path%>/project/vehicle/getCheckPrjPrdBscInfo.do';
        $.ajax({
            type: 'get',
            dataType:'json',
            data:{carNo:carNo},
            url: _url,
            success:function(msg){
                if(msg.success == 1){
                    if(msg.info == 1){
                        $.ligerDialog.confirm('车辆已存在，请核实车源编号！', function (flag) {
                            if(flag == false){
                                $.ligerDialog.hide();//关闭窗口
                                return;
                            }
                            $.ligerDialog.hide();//关闭窗口
                        });
                    }else {
                        var callback = frameElement.dialog.get("callback");
                        var id = selectedRows[0].id;
                        var purposeCd = selectedRows[0].carType;
                        console.log("车源id:"+selectedRows[0].id);
                        parent.Add_navTab('tab_project_prd_detail'+id,'项目产品详细信息','<%=path%>/project/vehicle/toPrjPrdDetailPage.do?carSourceId='+id+'&&prjId='+prjId + '&&purposeCd='+purposeCd,callback);
                        console.log("车源id:"+id);
                        parent.$.ligerDialog.close();
                        parent.$(".l-dialog,.l-window-mask").css("display","none");
                    }
                }else if(msg.success == 0){
                    top.$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                }
            }
        });
    }
    
    function clearBtn(){
        $("#carNo").val("");
    }
    
    function iframeResize () {
        if (parent.mainApp) {
            parent.mainApp.parentTab.onResize();
        };
    }
    //格式化时间
    function renderDate(rowdata, index, value){
        var dateStr = "";
        if(null != value){
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }

</script>

</body>
</html>